package com.cocoiko;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.cocoiko.customview.CocoikoListView;
import com.cocoiko.info.CocoikoInfo;

public class AllCocoiko extends Activity implements OnClickListener {

	Button friend_button;
	Button lead_button;
	Button all_button;

	CocoikoListView cocoiko_listview;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.allcocoiko);

		// get view widget
		friend_button = (Button) findViewById(R.id.friend);
		lead_button = (Button) findViewById(R.id.lead);
		all_button = (Button) findViewById(R.id.all);

		cocoiko_listview = (CocoikoListView) findViewById(R.id.cocoiko_list);

		// set action listener
		friend_button.setOnClickListener(this);
		lead_button.setOnClickListener(this);
		all_button.setOnClickListener(this);
		
	}
	//test list data
	public ArrayList<CocoikoInfo> getKokoikoInfo() {
		ArrayList<CocoikoInfo> infos = new ArrayList<CocoikoInfo>();

		// test
		Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
				R.drawable.icon);
		ArrayList<Bitmap> lead_avatar = new ArrayList<Bitmap>();
		lead_avatar.add(bitmap);
		lead_avatar.add(bitmap);

		CocoikoInfo info = new CocoikoInfo(bitmap, "comment", bitmap,
				"Shop name", "shop address", lead_avatar, "2011/11/1");
		infos.add(info);
		info = new CocoikoInfo(bitmap, "comment", null,
				"Shop name", "shop address", null, "2011/11/1");
		infos.add(info);
		return infos;

	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		Intent intent;
		switch (item.getItemId()) {
		case R.id.home:
			if (!this.getClass().getName().equals(Home.class.getName())) {
				intent = new Intent(this, Home.class);
				startActivity(intent);
				finish();
			}
			break;
		case R.id.friends:
			if (!this.getClass().getName().equals(Friends.class.getName())) {
				intent = new Intent(this, Friends.class);
				startActivity(intent);
				finish();
			}
			break;
		case R.id.map:
			if (!this.getClass().getName().equals(Map.class.getName())) {
				intent = new Intent(this, Map.class);
				startActivity(intent);
				finish();
			}
			break;
		case R.id.allkokoiko:
			if (!this.getClass().getName().equals(AllCocoiko.class.getName())) {
				intent = new Intent(this, AllCocoiko.class);
				startActivity(intent);
				finish();
			}
			break;
		case R.id.message:
			if (!this.getClass().getName().equals(Message.class.getName())) {
				intent = new Intent(this, Message.class);
				startActivity(intent);
				finish();
			}
			break;
		case R.id.setting:
			if (!this.getClass().getName().equals(Setting.class.getName())) {
				finish();
				intent = new Intent(this, Setting.class);
				startActivity(intent);
				finish();
			}
			break;
		}
		return true;
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		if (view == friend_button) {
			friend_cocoiko_update();
		}
		if (view == lead_button) {
			lead_cocoiko_update();
		}
		if (view == all_button) {
			all_cocoiko_update();
		}
	}

	/*
	 * all cocoiko button click
	 */
	private void all_cocoiko_update() {
		// TODO Auto-generated method stub
		//get info
		
		//insert into list
		cocoiko_listview.addDataIntoList(getKokoikoInfo());
	}
	/*
	 * lead cocoiko button click
	 */
	private void lead_cocoiko_update() {
		// TODO Auto-generated method stub
		//get info
		
		//insert into list
		cocoiko_listview.addDataIntoList(getKokoikoInfo());
	}
	/*
	 * friend cocoiko button click
	 */
	private void friend_cocoiko_update() {
		// TODO Auto-generated method stub
		//get info
		
		//insert into list
		cocoiko_listview.addDataIntoList(getKokoikoInfo());
	}
}
